/**
 * Filename:    WordReportTotalFeeServiceImpl.java
 * Copyright:   2015 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2015-3-9
 */

package com.paic.mhis.hcpms.quota.exportword.biz.service.impl;

import java.math.BigDecimal;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.paic.mhis.hcpms.common.document.util.Constant;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.biz.service.KpiCoreDataService;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiConditionDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiGradeDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiMedicalOrgDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiSociationDTO;
import com.paic.mhis.hcpms.quota.exportword.biz.service.WordReportTotalFeeService;
import com.paic.mhis.hcpms.quota.exportword.dao.WordDataDao;
import com.paic.mhis.hcpms.quota.exportword.dto.FeeCheckDTO;
import com.paic.mhis.hcpms.quota.exportword.dto.IndicatorWordDTO;
import com.paic.mhis.hcpms.quota.exportword.utils.GeneralMethods;
import com.paic.mhis.hcpms.quota.exportword.utils.WordReportCalculateHelper;
import com.paic.mhis.hcpms.quota.intergration.sao.FwaMonthlyReportSao;

import com.paic.mhis.hcpms.quota.settlement.common.Constants;
import com.paic.mhis.hcpms.quota.settlement.common.KpiValueConst;

/**
 * 
 * Description:word报告生成的第一二三大部分中总费用分析，总医保费用占比分析
 * @author:     EX-ZHANGJICHENG001
 * @version:1.0
 */
@Service("wordReportTotalFeeService")
public class WordReportTotalFeeImpl implements WordReportTotalFeeService {
	private static final Log LOG = LogFactory.getLog(WordReportTotalFeeImpl.class);

	@Autowired
	private FwaMonthlyReportSao fwaMonthlyReportSao;

	@Autowired
	private KpiCoreDataService kpiCoreDataService;

	@Autowired
	private WordDataDao wordDataDao;

	/**
	 * Description:  统筹区中医疗总费用分析  
	 * @param param 参数集合（指标编码、地区码、指标时间）
	 * @return  当期总费用，过去12个月的同比环比值集合，未来三个月预测值集合、同期平均值集合
	 * 
	 * 
	 */
	private Map<String, Object> getTotalFee(Map<String, Object> param, Map<String, String> kpiLimitParam) {

		String kpiCode = KpiValueConst.KPI0001;

		String endDate = (String) param.get("currentDate");
		String startDate = WordReportCalculateHelper.getInstance().getStartDate(endDate, -Constant.MONTH_THIRTYFIVE);
		Map<String, Integer> orderMapthirtySix = WordReportCalculateHelper.getInstance().createOrderList(startDate,
				endDate);
		// 同比
		List<BigDecimal> periodList = WordReportCalculateHelper.getInstance().createSetListValue(
				orderMapthirtySix.size(), new BigDecimal(0));
		// 环比
		List<BigDecimal> chainList = WordReportCalculateHelper.getInstance().createSetListValue(
				orderMapthirtySix.size(), new BigDecimal(0));
		// 总额
		List<BigDecimal> totalPayList = WordReportCalculateHelper.getInstance().createSetListValue(
				orderMapthirtySix.size(), new BigDecimal(0));

		List<KpiSociationDTO> dataList = queryKpiSociationDTO(param, kpiCode);

		getKpiSociationDTOKpiInfo(orderMapthirtySix, periodList, chainList, totalPayList, dataList);
		// 获取过去12个月总医疗费用同期平均值
		List<BigDecimal> monthAveValList = getMonthAverageValue(totalPayList);
		// 获取过去12个月总医疗费用值、同比增長率值，環比增長率值
		List<BigDecimal> monthTotalPayList = getMonthsList(totalPayList);
		List<BigDecimal> monthPeriodList = getMonthsList(periodList);
		List<BigDecimal> monthChainList = getMonthsList(chainList);
		// 获取过去12个月环比增长率总和平均值
		BigDecimal lastTweMonAveVal = getLastTwelveMonAve(monthChainList);
		// 获取要预测的3个月的医疗费用总值
		List<BigDecimal> threeAvePreTotValList = getThreeMonthpredictList(totalPayList, lastTweMonAveVal);

		// ----新计算方法---同比预测----环比预测--------------开始------------------------
		List<BigDecimal> threeYearPeriodPredict = getPeriodRatioPredict(threeAvePreTotValList, totalPayList,
				monthPeriodList);
		List<BigDecimal> threeYearChainPredict = getChainRatioPredict(threeAvePreTotValList, monthChainList);

		// ----新计算方法---------------------结束------------------------------

		Map<String, List<BigDecimal>> listToResult = new HashMap<String, List<BigDecimal>>();
		listToResult.put("monthTotalPayList", monthTotalPayList);
		listToResult.put("monthPeriodList", monthPeriodList);
		listToResult.put("monthChainList", monthChainList);
		listToResult.put("monthAverageValueList", monthAveValList);
		listToResult.put("threeAvePredictTotValList", threeAvePreTotValList);
		listToResult.put("threeAvePredictChainRatioValList", threeYearChainPredict);
		listToResult.put("threeAvePredictPeriodRatioValList", threeYearPeriodPredict);

		// 将处理结果转换成键值对输出到word中
		Map<String, Object> resultMap = getTotalFeeResult(listToResult, kpiLimitParam);

		return resultMap;
	}

	private List<BigDecimal> getPeriodRatioPredict(List<BigDecimal> threeAvePreTotValList,
			List<BigDecimal> totalPayList, List<BigDecimal> monthPeriodList) {
		List<BigDecimal> periodList = new ArrayList<BigDecimal>();
		BigDecimal firstMonPeriod = new BigDecimal(0);
		BigDecimal secondMonPeriod = new BigDecimal(0);
		BigDecimal thirdMonPeriod = new BigDecimal(0);
		if (totalPayList.get(Constant.MONTH_TWENTYFOUR).compareTo(new BigDecimal(0)) != 0) {
			firstMonPeriod = threeAvePreTotValList.get(Constant.INDEX_ONE)
					.subtract(totalPayList.get(Constant.MONTH_TWENTYFOUR))
					.divide(totalPayList.get(Constant.MONTH_TWENTYFOUR), Constant.NUMBER_TWO, BigDecimal.ROUND_HALF_UP);
		}
		if (totalPayList.get(Constant.MONTH_TWENTYFIVE).compareTo(new BigDecimal(0)) != 0) {
			secondMonPeriod = threeAvePreTotValList.get(Constant.INDEX_TWO)
					.subtract(totalPayList.get(Constant.MONTH_TWENTYFIVE))
					.divide(totalPayList.get(Constant.MONTH_TWENTYFIVE), Constant.NUMBER_TWO, BigDecimal.ROUND_HALF_UP);
		}

		if (totalPayList.get(Constant.MONTH_TWENTYSIX).compareTo(new BigDecimal(0)) != 0) {
			thirdMonPeriod = threeAvePreTotValList.get(Constant.INDEX_THREE)
					.subtract(totalPayList.get(Constant.MONTH_TWENTYSIX))
					.divide(totalPayList.get(Constant.MONTH_TWENTYSIX), Constant.NUMBER_TWO, BigDecimal.ROUND_HALF_UP);
		}
		periodList.add(monthPeriodList.get(Constant.INDEX_ELEVEN));
		periodList.add(firstMonPeriod);
		periodList.add(secondMonPeriod);
		periodList.add(thirdMonPeriod);

		return periodList;
	}

	private List<BigDecimal> getChainRatioPredict(List<BigDecimal> threeAvePreTotValList,
			List<BigDecimal> monthChainList) {
		List<BigDecimal> chainList = new ArrayList<BigDecimal>();
		BigDecimal chain = new BigDecimal(0);
		for (int i = 0; i < threeAvePreTotValList.size() - Constant.NUMBER_ONE; i++) {
			if (threeAvePreTotValList.get(i).compareTo(new BigDecimal(0)) != 0) {
				chain = (threeAvePreTotValList.get(i + Constant.NUMBER_ONE).subtract(threeAvePreTotValList.get(i)))
						.divide(threeAvePreTotValList.get(i), Constant.NUMBER_TWO, BigDecimal.ROUND_HALF_UP);
			}
			chainList.add(chain);
		}
		chainList.add(0, monthChainList.get(Constant.INDEX_ELEVEN));
		return chainList;
	}

	private void getKpiSociationDTOKpiInfo(Map<String, Integer> orderMapthirtySix, List<BigDecimal> periodList,
			List<BigDecimal> chainList, List<BigDecimal> totalPayList, List<KpiSociationDTO> dataList) {
		String kpiTime;
		BigDecimal periodRatio;
		BigDecimal chainRatio;
		BigDecimal kpiValue;
		for (KpiSociationDTO kpiSociationDTO : dataList) {
			kpiValue = kpiSociationDTO.getKpiValue();
			periodRatio = kpiSociationDTO.getPeriodRatio();
			chainRatio = kpiSociationDTO.getChainRatio();
			kpiTime = GeneralMethods.getInstance().replacTimeFormate(kpiSociationDTO.getKpiTime());
			// 医疗总额
			periodList.set(orderMapthirtySix.get(kpiTime),
					WordReportCalculateHelper.getInstance().filterNullValue(periodRatio));
			chainList.set(orderMapthirtySix.get(kpiTime),
					WordReportCalculateHelper.getInstance().filterNullValue(chainRatio));
			totalPayList.set(orderMapthirtySix.get(kpiTime),
					WordReportCalculateHelper.getInstance().filterNullValue(kpiValue));
		}
	}

	private Map<String, Object> getTotalFeeResult(Map<String, List<BigDecimal>> map, Map<String, String> kpiLimitParam) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put(
				"k0_1_1_1_totalFee_end",
				GeneralMethods.getInstance().toFix2Digits(
						WordReportCalculateHelper.getInstance().toFixedList(map.get("monthTotalPayList"))
								.get(Constant.MONTH_ELEVEN).doubleValue()));
		resultMap.put(
				"k0_1_1_1_mom_end",
				GeneralMethods.getInstance().toFix2Digits(
						map.get("monthChainList").get(Constant.MONTH_ELEVEN).abs().doubleValue()));
		resultMap.put(
				"k0_1_1_1_yoy_end",
				GeneralMethods.getInstance().toFix2Digits(
						map.get("monthPeriodList").get(Constant.MONTH_ELEVEN).abs().doubleValue()));
		resultMap.put("k0_1_1_1_totalFee_gqsnList_end",
				WordReportCalculateHelper.getInstance().toFixedList(map.get("monthAverageValueList")));
		resultMap.put("k0_1_1_1_totalFee_yc_momList_end", map.get("monthChainList"));
		resultMap.put("k0_1_1_1_totalFee_yc_yoyList_end", map.get("monthPeriodList"));
		resultMap.put("k0_1_1_1_totalFee_gqynList_end",
				WordReportCalculateHelper.getInstance().toFixedList(map.get("monthTotalPayList")));
		resultMap.put("k0_1_1_1_totalFee_wlsyList_end",
				WordReportCalculateHelper.getInstance().toFixedList(map.get("threeAvePredictTotValList")));
		resultMap.put("k0_1_1_1_totalFee_yc_yoy_ycList_end", WordReportCalculateHelper.getInstance()
				.toFixedPercentList(map.get("threeAvePredictPeriodRatioValList")));
		resultMap.put("k0_1_1_1_totalFee_yc_mom_ycList_end", WordReportCalculateHelper.getInstance()
				.toFixedPercentList(map.get("threeAvePredictChainRatioValList")));

		resultMap.put(
				"k0_1_1_1_health_flag_end",
				WordReportCalculateHelper.getInstance().getTotalFeeTendencyMessage(map.get("monthChainList"),
						map.get("monthPeriodList"), kpiLimitParam));
		resultMap.put("k0_1_1_1_mom_flag_end",
				WordReportCalculateHelper.getInstance().getRatioCompareResult(map.get("monthChainList")));
		resultMap.put("k0_1_1_1_yoy_flag_end",
				WordReportCalculateHelper.getInstance().getRatioCompareResult(map.get("monthPeriodList")));
		resultMap.put(
				"k0_1_1_1_mom_result_end",
				WordReportCalculateHelper.getInstance().getRatioCompareScope(map.get("monthChainList"),
						kpiLimitParam.get("chainUpper"), kpiLimitParam.get("chainDown")));
		resultMap.put(
				"k0_1_1_1_yoy_result_end",
				WordReportCalculateHelper.getInstance().getRatioCompareScope(map.get("monthPeriodList"),
						kpiLimitParam.get("periodUpper"), kpiLimitParam.get("periodDown")));
		resultMap.put(
				"k0_1_1_1_health_flag2_end",
				WordReportCalculateHelper.getInstance().getRiskMessage(map.get("threeAvePredictPeriodRatioValList"),
						map.get("threeAvePredictChainRatioValList"), kpiLimitParam));

		checkTotalFeeLimitNull(kpiLimitParam, resultMap);
		return resultMap;
	}

	private void checkTotalFeeLimitNull(Map<String, String> kpiLimitParam, Map<String, Object> resultMap) {
		if (GeneralMethods.getInstance().isEmptyString(kpiLimitParam.get("periodUpper"))) {
			resultMap.put("KPI0001_yoy_upper_end", " ");
		} else {
			resultMap.put("KPI0001_yoy_upper_end", kpiLimitParam.get("periodUpper"));
		}
		if (GeneralMethods.getInstance().isEmptyString(kpiLimitParam.get("periodDown"))) {
			resultMap.put("KPI0001_yoy_lower_end", " ");
		} else {
			resultMap.put("KPI0001_yoy_lower_end", kpiLimitParam.get("periodDown"));
		}
		if (GeneralMethods.getInstance().isEmptyString(kpiLimitParam.get("chainUpper"))) {
			resultMap.put("KPI0001_mom_upper_end", " ");
		} else {
			resultMap.put("KPI0001_mom_upper_end", kpiLimitParam.get("chainUpper"));
		}
		if (GeneralMethods.getInstance().isEmptyString(kpiLimitParam.get("chainDown"))) {
			resultMap.put("KPI0001_mom_lower_end", " ");
		} else {
			resultMap.put("KPI0001_mom_lower_end", kpiLimitParam.get("chainDown"));
		}
	}

	private List<KpiSociationDTO> queryKpiSociationDTO(Map<String, Object> param, String kpiCode) {
		String regionCode = (String) param.get("regionCode");
		KpiConditionDTO conditionDTO = new KpiConditionDTO();
		List<String> kpiCodeList = new ArrayList<String>();
		kpiCodeList.add(kpiCode);
		conditionDTO.setKpiCodeList(kpiCodeList);
		conditionDTO.setSociationCode(regionCode);
		conditionDTO.setVisitType(Constant.VISIT_TYPE_ZERO);
		conditionDTO.setPeriod(Constant.TIME_TYPE_MONTH);
		String endDate = (String) param.get("currentDate");
		String startDate = WordReportCalculateHelper.getInstance().getStartDate(endDate, -Constant.MONTH_THIRTYFIVE);
		conditionDTO.setKpiTimeStart(startDate);
		conditionDTO.setKpiTimeEnd(endDate);

		List<KpiSociationDTO> dataList = kpiCoreDataService.queryKpiBySoc(conditionDTO);
		return dataList;

	}

	// 获取过去12个月总医疗费用、总医保费用占比同期平均值
	private List<BigDecimal> getMonthAverageValue(List<BigDecimal> tatalPayList) {

		List<BigDecimal> newMonthAverageValueList = new ArrayList<BigDecimal>();
		for (int i = 0; i < Constant.MONTH_TWELVE; i++) {
			BigDecimal average = new BigDecimal(0);
			BigDecimal average1 = tatalPayList.get(i);
			BigDecimal average2 = tatalPayList.get(i + Constant.MONTH_TWELVE);
			BigDecimal average3 = tatalPayList.get(i + Constant.MONTH_TWENTYFOUR);
			average = average.add(average1).add(average2).add(average3);
			average = average.divide(new BigDecimal(Constant.NUMBER_THREE), Constant.NUMBER_TWO,
					BigDecimal.ROUND_HALF_UP);
			newMonthAverageValueList.add(average);
		}

		return newMonthAverageValueList;
	}

	// 获取过去12个月总医疗费用值、同比增長率值，環比增長率值
	private List<BigDecimal> getMonthsList(List<BigDecimal> list) {
		List<BigDecimal> lastTwelveData = new ArrayList<BigDecimal>();
		for (int i = 0; i < Constant.MONTH_TWELVE; i++) {
			BigDecimal number = list.get(i + Constant.MONTH_TWENTYFOUR);
			lastTwelveData.add(number);
		}
		return lastTwelveData;
	}

	// 获取过去12个月环比增长率总和平均值
	private BigDecimal getLastTwelveMonAve(List<BigDecimal> twelveMonthList) {
		BigDecimal totalValue = new BigDecimal(0);
		for (int i = 0; i < twelveMonthList.size(); i++) {
			BigDecimal value = twelveMonthList.get(i);
			totalValue = totalValue.add(value);
		}
		return totalValue.divide(new BigDecimal(Constant.NUMBER_TWELVE), Constant.NUMBER_TWO, BigDecimal.ROUND_HALF_UP);
	}

	// 获取要预测的3个月的医疗费用总值或总医疗费用占比
	private List<BigDecimal> getThreeMonthpredictList(List<BigDecimal> list, BigDecimal averageNumber) {
		BigDecimal currentNumber = averageNumber.divide(new BigDecimal(Constant.NUMBER_HUNDRED), Constant.NUMBER_TWO,
				BigDecimal.ROUND_HALF_UP);
		List<BigDecimal> threeMonthPredict = new ArrayList<BigDecimal>();
		BigDecimal currentVal = list.get(Constant.MONTH_THIRTYFIVE);
		for (int i = 0; i < Constant.MONTH_THIRD; i++) {
			BigDecimal atFirst = new BigDecimal(0);
			BigDecimal firstMonth = list.get(i);
			BigDecimal secondMonth = list.get(i + Constant.MONTH_TWELVE);
			BigDecimal thirdMonth = list.get(i + Constant.MONTH_TWENTYFOUR);
			BigDecimal averageData = atFirst.add(firstMonth).add(secondMonth).add(thirdMonth);
			averageData = averageData.divide(new BigDecimal(Constant.NUMBER_THREE), Constant.NUMBER_TWO,
					BigDecimal.ROUND_HALF_UP);
			BigDecimal data = averageData.multiply(new BigDecimal(1).add(currentNumber));
			threeMonthPredict.add(data);
		}
		threeMonthPredict.add(0, currentVal);
		return threeMonthPredict;
	}

	/**
	 * Description:  报告第二部分指定时间内各级别总费用情况，医保费用占比情况
	 * @param param 指标编码、统筹区、指标时间
	 * @return 各级别医疗机构总费用集合，各级别医保费用占比集合
	 * 
	 */
	private Map<String, Object> getKipMapAll(Map<String, Object> param) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String date = (String) param.get("currentDate");
		String regionCode = (String) param.get("regionCode");
		String visitType = Constant.VISIT_TYPE_ZERO;
		String kpiCode = KpiValueConst.KPI0001;
		KpiConditionDTO condition = new KpiConditionDTO();
		KpiConditionDTO conditionDTO = getKpiConditionDtoInfo(date, regionCode, visitType, kpiCode);
		List<KpiSociationDTO> dataList = kpiCoreDataService.queryKpiBySoc(conditionDTO);
		condition.setVisitType(visitType);
		condition.setKpiTime(date);
		condition.setKpiCode(kpiCode);
		condition.setSociationCode(regionCode);
		Map<String, Object> map1 = getKipMap(condition);
		kpiCode = KpiValueConst.KPI0002;
		KpiConditionDTO conditionDTOPercent = getKpiConditionDtoInfo(date, regionCode, visitType, kpiCode);
		List<KpiSociationDTO> dataPercentList = kpiCoreDataService.queryKpiBySoc(conditionDTOPercent);
		condition.setKpiCode(kpiCode);
		Map<String, Object> map2 = getKipMap(condition);

		String[] levelL1 = new String[Constant.NUMBER_SEVEN];
		String[] levelL2 = new String[Constant.NUMBER_SEVEN];
		String[] levelL3 = new String[Constant.NUMBER_SEVEN];
		String[] levelTotal = new String[Constant.NUMBER_SEVEN];
		System.arraycopy((String[]) map1.get("totalFeeL3"), 0, levelL3, 0, Constant.NUMBER_FOUR);
		System.arraycopy((String[]) map2.get("totalFeePercentL3"), 1, levelL3, Constant.NUMBER_FOUR,
				Constant.NUMBER_THREE);
		System.arraycopy((String[]) map1.get("totalFeeL2"), 0, levelL2, 0, Constant.NUMBER_FOUR);
		System.arraycopy((String[]) map2.get("totalFeePercentL2"), 1, levelL2, Constant.NUMBER_FOUR,
				Constant.NUMBER_THREE);
		System.arraycopy((String[]) map1.get("totalFeeL1"), 0, levelL1, 0, Constant.NUMBER_FOUR);
		System.arraycopy((String[]) map2.get("totalFeePercentL1"), 1, levelL1, Constant.NUMBER_FOUR,
				Constant.NUMBER_THREE);
		levelTotal[0] = "合计：";
		if (GeneralMethods.getInstance().isNotEmptyCollects(dataList)) {
			levelTotal[1] = WordReportCalculateHelper.getInstance().yuanToTenThousands(dataList.get(0).getKpiValue())
					.toString();
		} else {
			levelTotal[1] = new BigDecimal(0).toString();
		}
		if (GeneralMethods.getInstance().isNotEmptyCollects(dataPercentList)) {
			levelTotal[4] = dataPercentList.get(0).getKpiValue()
					.divide(new BigDecimal(1), Constant.NUMBER_TWO, BigDecimal.ROUND_HALF_UP).toString();
		} else {
			levelTotal[4] = new BigDecimal(0).toString();
		}
		List<String[]> resultList = new ArrayList<String[]>();
		resultList.add(levelL3);
		resultList.add(levelL2);
		resultList.add(levelL1);
		resultList.add(levelTotal);
		resultMap.put("k1_1_1_1_tableList_end", resultList);
		return resultMap;
	}

	private KpiConditionDTO getKpiConditionDtoInfo(String date, String regionCode, String visitType, String kpiCode) {
		KpiConditionDTO conditionDTO = new KpiConditionDTO();
		List<String> kpiCodeList = new ArrayList<String>();
		kpiCodeList.add(kpiCode);
		conditionDTO.setKpiCodeList(kpiCodeList);
		conditionDTO.setSociationCode(regionCode);
		conditionDTO.setVisitType(visitType);// 总费用类型
		conditionDTO.setPeriod(Constant.TIME_TYPE_MONTH);// 按月份查找
		conditionDTO.setKpiTime(date);
		return conditionDTO;
	}

	// 一二三级医疗机构，医疗机构占比
	private Map<String, Object> getKipMap(KpiConditionDTO condition) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<KpiGradeDTO> kpiGrades = kpiCoreDataService.queryKpiByGrade(condition);
		// 存储一级的集合
		List<KpiGradeDTO> grade1 = new ArrayList<KpiGradeDTO>();
		// 存储二级的集合
		List<KpiGradeDTO> grade2 = new ArrayList<KpiGradeDTO>();
		// 存储三级的集合
		List<KpiGradeDTO> grade3 = new ArrayList<KpiGradeDTO>();
		BigDecimal chainRatio1 = new BigDecimal(0);
		BigDecimal periodRatio1 = new BigDecimal(0);
		BigDecimal chainRatio2 = new BigDecimal(0);
		BigDecimal periodRatio2 = new BigDecimal(0);
		BigDecimal chainRatio3 = new BigDecimal(0);
		BigDecimal periodRatio3 = new BigDecimal(0);
		getGradeDTO(kpiGrades, grade1, grade2, grade3);
		// 存储指标类型总 指标医院级别,合计 总
		BigDecimal allNum = new BigDecimal(0);
		// 一级 总
		BigDecimal allNum1 = new BigDecimal(0);
		// 二级 总
		BigDecimal allNum2 = new BigDecimal(0);
		// 三级 总
		BigDecimal allNum3 = new BigDecimal(0);
		List<BigDecimal> listGrade1 = getKpiGradeData(allNum, allNum1, grade1, chainRatio1, periodRatio1);
		List<BigDecimal> listGrade2 = getKpiGradeData(allNum, allNum2, grade2, chainRatio2, periodRatio2);
		List<BigDecimal> listGrade3 = getKpiGradeData(allNum, allNum3, grade3, chainRatio3, periodRatio3);
		allNum = listGrade1.get(0).add(listGrade2.get(0)).add(listGrade3.get(0));

		String[] level1 = new String[Constant.NUMBER_FOUR];
		String[] level2 = new String[Constant.NUMBER_FOUR];
		String[] level3 = new String[Constant.NUMBER_FOUR];
		String[] levelTotal = new String[Constant.NUMBER_FOUR];
		if ("KPI0001".equals(condition.getKpiCode())) {
			level3[0] = "三级医院";
			level3[1] = WordReportCalculateHelper.getInstance()
					.toFixedTwoPercent(WordReportCalculateHelper.getInstance().yuanToTenThousands(listGrade3.get(1)))
					.toString();
			level3[2] = "" + listGrade3.get(Constant.NUMBER_THREE);
			level3[3] = "" + listGrade3.get(Constant.NUMBER_TWO);
			level2[0] = "二级医院";
			level2[1] = WordReportCalculateHelper.getInstance()
					.toFixedTwoPercent(WordReportCalculateHelper.getInstance().yuanToTenThousands(listGrade2.get(1)))
					.toString();
			level2[2] = "" + listGrade2.get(Constant.NUMBER_THREE);
			level2[3] = "" + listGrade2.get(Constant.NUMBER_TWO);
			level1[0] = "一级及以下医院";
			level1[1] = WordReportCalculateHelper.getInstance()
					.toFixedTwoPercent(WordReportCalculateHelper.getInstance().yuanToTenThousands(listGrade1.get(1)))
					.toString();
			level1[2] = "" + listGrade1.get(Constant.NUMBER_THREE);
			level1[3] = "" + listGrade1.get(Constant.NUMBER_TWO);
			levelTotal[0] = WordReportCalculateHelper.getInstance().yuanToTenThousands(allNum).toString();

			map.put("totalFee", levelTotal);
			map.put("totalFeeL1", level1);
			map.put("totalFeeL2", level2);
			map.put("totalFeeL3", level3);
		}
		if ("KPI0002".equals(condition.getKpiCode())) {
			level3[0] = "三级医院";
			level3[1] = listGrade3.get(1).setScale(Constant.NUMBER_TWO, BigDecimal.ROUND_HALF_UP).toString();
			level3[2] = "" + listGrade3.get(Constant.NUMBER_THREE);
			level3[3] = "" + listGrade3.get(Constant.NUMBER_TWO);
			level2[0] = "二级医院";
			level2[1] = listGrade2.get(1).setScale(Constant.NUMBER_TWO, BigDecimal.ROUND_HALF_UP).toString();
			level2[2] = "" + listGrade2.get(Constant.NUMBER_THREE);
			level2[3] = "" + listGrade2.get(Constant.NUMBER_TWO);
			level1[0] = "一级及以下医院";
			level1[1] = listGrade1.get(1).setScale(Constant.NUMBER_TWO, BigDecimal.ROUND_HALF_UP).toString();
			level1[2] = "" + listGrade1.get(Constant.NUMBER_THREE);
			level1[3] = "" + listGrade1.get(Constant.NUMBER_TWO);
			levelTotal[0] = allNum.setScale(Constant.NUMBER_TWO, BigDecimal.ROUND_HALF_UP).toString();

			map.put("totalFeePercent", levelTotal);
			map.put("totalFeePercentL1", level1);
			map.put("totalFeePercentL2", level2);
			map.put("totalFeePercentL3", level3);
		}
		return map;
	}

	private void getGradeDTO(List<KpiGradeDTO> kpiGrades, List<KpiGradeDTO> grade1, List<KpiGradeDTO> grade2,
			List<KpiGradeDTO> grade3) {
		if (GeneralMethods.getInstance().isNotEmptyCollects(kpiGrades)) {
			for (KpiGradeDTO dto : kpiGrades) {
				if (Constants.type_4.equals(dto.getGrade())) {
					grade1.add(dto);
				} else if (Constants.type_3.equals(dto.getGrade())) {
					grade2.add(dto);
				} else if (Constants.type_2.equals(dto.getGrade())) {
					grade3.add(dto);
				}
			}
		}
	}

	private List<BigDecimal> getKpiGradeData(BigDecimal totalNumber, BigDecimal gradeNumber, List<KpiGradeDTO> grade,
			BigDecimal chainRatio, BigDecimal periodRatio) {
		BigDecimal gradeNum = gradeNumber;
		BigDecimal totalNum = totalNumber;
		BigDecimal chainRat = chainRatio;
		BigDecimal periodRat = periodRatio;
		List<BigDecimal> listResult = new ArrayList<BigDecimal>();
		for (KpiGradeDTO dto : grade) {
			if (null != dto.getKpiValue()) {
				gradeNum = gradeNumber.add(dto.getKpiValue());
				totalNum = totalNumber.add(dto.getKpiValue());
			} else {
				gradeNum = gradeNumber.add(new BigDecimal(0));
				totalNum = totalNumber.add(new BigDecimal(0));
			}

			if (null != dto.getChainRatio()) {
				chainRat = chainRatio.add(dto.getChainRatio());
			} else {
				chainRat = new BigDecimal(0);
			}

			if (null != dto.getPeriodRatio()) {
				periodRat = periodRatio.add(dto.getPeriodRatio());
			} else {
				periodRat = new BigDecimal(0);
			}

		}

		listResult.add(new BigDecimal(WordReportCalculateHelper.getInstance().toFixedTwoPercent(totalNum)));
		listResult.add(new BigDecimal(WordReportCalculateHelper.getInstance().toFixedTwoPercent(gradeNum)));
		listResult.add(new BigDecimal(WordReportCalculateHelper.getInstance().toFixedTwoPercent(chainRat)));
		listResult.add(new BigDecimal(WordReportCalculateHelper.getInstance().toFixedTwoPercent(periodRat)));
		return listResult;
	}

	/**
	 * Description:   单一机构总费用情况 
	 * @param param 统筹区编码、指标编码、指标时间、机构编码
	 * @return 指定机构当期总费用、指定机构过去三年同期平均值集合，指定机构过去12各月费用值集合，同比环比集合等
	 * 
	 *
	 */
	private Map<String, Object> getUniqueMedicalFee(Map<String, Object> param, Map<String, String> kpiLimitParam) {

		String regionCode = (String) param.get("regionCode");
		KpiConditionDTO conditionDTO = new KpiConditionDTO();
		List<String> kpiCodeList = new ArrayList<String>();
		kpiCodeList.add(KpiValueConst.KPI0001);
		conditionDTO.setOrgCode((String) param.get("medicalOrgCode"));
		conditionDTO.setKpiCodeList(kpiCodeList);
		conditionDTO.setSociationCode(regionCode);
		conditionDTO.setVisitType(Constant.VISIT_TYPE_ZERO);
		conditionDTO.setPeriod(Constant.TIME_TYPE_MONTH);
		String endDate = (String) param.get("currentDate");
		String startDate = WordReportCalculateHelper.getInstance().getStartDate(endDate, -Constant.MONTH_THIRTYFIVE);
		conditionDTO.setKpiTimeStart(startDate);
		conditionDTO.setKpiTimeEnd(endDate);

		Map<String, Integer> orderMapthirtySix = WordReportCalculateHelper.getInstance().createOrderList(startDate,
				endDate);
		// 同比
		List<BigDecimal> periodList = WordReportCalculateHelper.getInstance().createSetListValue(
				orderMapthirtySix.size(), new BigDecimal(0));
		// 环比
		List<BigDecimal> chainList = WordReportCalculateHelper.getInstance().createSetListValue(
				orderMapthirtySix.size(), new BigDecimal(0));
		// 总额
		List<BigDecimal> totalPayList = WordReportCalculateHelper.getInstance().createSetListValue(
				orderMapthirtySix.size(), new BigDecimal(0));

		List<KpiMedicalOrgDTO> kpiMedicalOrgList = kpiCoreDataService.queryKpiByOrg(conditionDTO);
		// 对数据库中查找到的对象进行数据处理
		getMedicalOrgDTOKpiInfo(orderMapthirtySix, periodList, chainList, totalPayList, kpiMedicalOrgList);
		// 单一机构总费用占比过去12个月同期平均值
		List<BigDecimal> monthAverageValueList = getMonthAverageValue(totalPayList);
		// 过去12个月的单一机构总用，同比值，环比值
		List<BigDecimal> monthTotalPayList = getMonthsList(totalPayList);
		List<BigDecimal> monthPeriodList = getMonthsList(periodList);
		List<BigDecimal> monthChainList = getMonthsList(chainList);
		// 获取过去12个月环比增长率总和平均值
		BigDecimal lastTwelveMonthAverageValue = getLastTwelveMonAve(monthChainList);
		// 获取未来三个月单一机构总费用值
		List<BigDecimal> threeAvePredictTotValList = getThreeMonthpredictList(totalPayList, lastTwelveMonthAverageValue);

		// ----新计算方法---------------------开始------------------------
		// 同比预测
		List<BigDecimal> threeYearPeriodPredict = getPeriodRatioPredict(threeAvePredictTotValList, totalPayList,
				monthPeriodList);
		// 环比预测
		List<BigDecimal> threeYearChainPredict = getChainRatioPredict(threeAvePredictTotValList, monthChainList);

		// ----新计算方法---------------------结束------------------------------

		Map<String, List<BigDecimal>> listToResult = new HashMap<String, List<BigDecimal>>();
		listToResult.put("monthTotalPayList", monthTotalPayList);
		listToResult.put("monthPeriodList", monthPeriodList);
		listToResult.put("monthChainList", monthChainList);
		listToResult.put("monthAverageValueList", monthAverageValueList);
		listToResult.put("threeAvePredictTotValList", threeAvePredictTotValList);
		listToResult.put("threeAvePredictChainRatioValList", threeYearChainPredict);
		listToResult.put("threeAvePredictPeriodRatioValList", threeYearPeriodPredict);
		// 将结果封装成对应键值对返回
		Map<String, Object> resultMap = getUniqueMedicalFeeResult(listToResult, kpiLimitParam);
		return resultMap;
	}

	/**
	 * 
	 * 查询所有的住院或者门诊费用数据
	 * @param param
	 * @return 
	 */
	private Map<String, List<FeeCheckDTO>> queryAllHospitalFee(Map<String, Object> param,
			Map<String, List<FeeCheckDTO>> feeCheckReslt) {
		Map<String, String> queryFeeForDept = new HashMap<String, String>();
		queryFeeForDept.put("healthcareProviderCode", (String) param.get("medicalOrgCode"));
		queryFeeForDept.put("date", (String) param.get("currentDate"));
		queryFeeForDept.put("kpiCode", "KPI0071");
		queryFeeForDept.put("visitType", "1");
		queryFeeForDept.put("sociationCode", (String) param.get("regionCode"));
		// 得到每个科室的住院费用
		List<IndicatorWordDTO> listForHospital = wordDataDao.queryWorkDept(queryFeeForDept);

		// 1.fwa接口需要参数（住院）
		Map<String, String> params = new HashMap<String, String>();
		params.put("medicalOrgCode", (String) param.get("medicalOrgCode"));
		params.put("month", (String) param.get("currentDate"));
		params.put("visitType", "1");
		// 得到每个科室住院所有数据对应的Dto
		List<Map<String, Object>> hosMonthFeeFromFWA = getMonthFeeFromFWA(params);
		List<FeeCheckDTO> hospitalRefuFeeList = getRefuMonthFeeData(hosMonthFeeFromFWA, listForHospital);
		List<FeeCheckDTO> hospitalSuspFeeList = getSuspMonthFeeData(hosMonthFeeFromFWA, listForHospital);

		// 每个科室的 门诊住院费用
		queryFeeForDept.put("visitType", "2");
		List<IndicatorWordDTO> listForOutpatients = wordDataDao.queryWorkDept(queryFeeForDept);
		// fwa接口门诊所需参数
		params.put("visitType", "2");
		List<Map<String, Object>> outMonthFeeFromFWA = getMonthFeeFromFWA(params);
		// 得到每个科室门诊所有数据对应的DTo
		List<FeeCheckDTO> outRefuFeeList = getRefuMonthFeeData(outMonthFeeFromFWA, listForOutpatients);
		List<FeeCheckDTO> outSuspFeeList = getSuspMonthFeeData(outMonthFeeFromFWA, listForOutpatients);

		feeCheckReslt.put("hospitalRefuFeeList", hospitalRefuFeeList);
		feeCheckReslt.put("hospitalSuspFeeList", hospitalSuspFeeList);
		feeCheckReslt.put("outRefuFeeList", outRefuFeeList);
		feeCheckReslt.put("outSuspFeeList", outSuspFeeList);

		return feeCheckReslt;
	}

	private List<Map<String, Object>> getMonthFeeFromFWA(Map<String, String> params) {
		// 2. 查询所有数据
		List<Map<String, Object>> queryMedicalOrgInfo = new ArrayList<Map<String, Object>>();
		try {
			LOG.info("---------调用FWA接口-------------------------");
			queryMedicalOrgInfo = fwaMonthlyReportSao.invokeMonthlyReportInfoESA(params.get("medicalOrgCode"),
					params.get("month"), params.get("visitType"));
			LOG.info("----返回FWA接口数据---" + queryMedicalOrgInfo);
		} catch (Exception e) {
			LOG.error("-select FWA port Exception:", e);
		}
		return queryMedicalOrgInfo;
	}

	/**
	 * 
	 * 得到每个科室的可疑和拒付百分比
	 * @param hospitalFeeList
	 */
	private void getMonthPercent(FeeCheckDTO hospitalFee) {
		String outOfLineAmount = hospitalFee.getOutOfLineAmount();
		String suspiciousAmount = hospitalFee.getSuspiciousAmount();
		String kpiValue = hospitalFee.getKpiValue();
		// 得到某个可疑金额占比
		double suspAmountPercent = getDeptPrecent(kpiValue, suspiciousAmount).doubleValue();
		// 拒付金额占比
		double outAmountPercent = getOutAmountPrecent(kpiValue, outOfLineAmount).doubleValue();
		hospitalFee.setSuspAmountPercent(suspAmountPercent);
		hospitalFee.setOutAmountPercent(outAmountPercent);
	}

	/**
	 * 
	 * 查询每个科室对应DTO
	 * @param hosFeeForDeptList
	 * @param params
	 * @return
	 */
	private List<FeeCheckDTO> getRefuMonthFeeData(List<Map<String, Object>> queryMedicalOrgInfo,
			List<IndicatorWordDTO> hosFeeForDeptList) {
		List<FeeCheckDTO> monthFee = new ArrayList<FeeCheckDTO>();
		for (int i = 0; i < queryMedicalOrgInfo.size(); i++) {
			FeeCheckDTO feeCheck = new FeeCheckDTO();
			// 科室编码
			String medicalDeptCode = (String) queryMedicalOrgInfo.get(i).get("medicalDeptCode");
			if (StringUtils.isBlank(medicalDeptCode)) {
				continue;
			}
			// 比较科室编码
			String findStatus = compareWorkdepCode(hosFeeForDeptList, feeCheck, medicalDeptCode);
			if (StringUtils.equals(findStatus, "1")) {
				continue;
			}
			String refuAmout = queryMedicalOrgInfo.get(i).get("outOfLine").toString();
			if (StringUtils.equals(findStatus, "0")) {
				BigDecimal outAmount = new BigDecimal(refuAmout);
				if (!(outAmount.compareTo(new BigDecimal(0)) == 0)) {
					continue;
				}
			}

			feeCheck.setOutOfLineAmount(refuAmout);
			// 得到每个月的审查的百分比 门诊的
			getMonthPercent(feeCheck);

			if (new BigDecimal(refuAmout).compareTo(new BigDecimal("0")) > 0) {
				monthFee.add(feeCheck);
			}
		}
		return monthFee;
	}

	/**
	 * 
	 * 查询每个科室对应DTO
	 * @param hosFeeForDeptList
	 * @param params
	 * @return
	 */
	private List<FeeCheckDTO> getSuspMonthFeeData(List<Map<String, Object>> queryMedicalOrgInfo,
			List<IndicatorWordDTO> hosFeeForDeptList) {
		List<FeeCheckDTO> monthFee = new ArrayList<FeeCheckDTO>();
		for (int i = 0; i < queryMedicalOrgInfo.size(); i++) {
			FeeCheckDTO feeCheck = new FeeCheckDTO();
			// 科室编码
			String medicalDeptCode = (String) queryMedicalOrgInfo.get(i).get("medicalDeptCode");
			if (StringUtils.isBlank(medicalDeptCode)) {
				continue;
			}
			// 比较科室编码
			String findStatus = compareWorkdepCode(hosFeeForDeptList, feeCheck, medicalDeptCode);
			if (StringUtils.equals(findStatus, "1")) {
				continue;
			}
			String suspAmout = queryMedicalOrgInfo.get(i).get("suspicious").toString();
			if (StringUtils.equals(findStatus, "0")) {
				BigDecimal suspAmount = new BigDecimal(suspAmout);
				if (!(suspAmount.compareTo(new BigDecimal(0)) == 0)) {
					continue;
				}
			}
			feeCheck.setSuspiciousAmount(suspAmout);
			// 得到每个月的审查的百分比 门诊的
			getMonthPercent(feeCheck);

			if (new BigDecimal(suspAmout).compareTo(new BigDecimal("0")) > 0) {
				monthFee.add(feeCheck);
			}
		}
		return monthFee;
	}

	/**
	 * 
	 * 找到对应的的科室编码，得到住院费用
	 * @param hosFeeForDeptList
	 * @param feeCheck
	 * @param medicalDeptCode
	 * @return
	 */
	private String compareWorkdepCode(List<IndicatorWordDTO> hosFeeForDeptList, FeeCheckDTO feeCheck,
			String medicalDeptCode) {
		Boolean flag = false;
		for (int j = 0; j < hosFeeForDeptList.size(); j++) {
			// 得到医院的科室编码(不为空)
			String workdepCode = hosFeeForDeptList.get(j).getWorkdepCode();
			if (StringUtils.equals(medicalDeptCode, workdepCode)) {
				flag = true;
				String kpi = hosFeeForDeptList.get(j).getKpiValue();
				// 查询出住院费用为0处理
				if (new BigDecimal(0).compareTo(new BigDecimal(kpi)) == 0) {
					return "0";
				}
				feeCheck.setDeptName(hosFeeForDeptList.get(j).getWorkDept());
				feeCheck.setKpiValue(hosFeeForDeptList.get(j).getKpiValue());
				break;
			}
		}
		// 如果没有发现对应的，就返回1
		if (!flag) {
			return "1";
		}
		return "2";
	}

	/**
	 * 
	 * 得到某个可疑金额占比
	 * @return
	 */
	private BigDecimal getDeptPrecent(String hospitalTotal, String suspiciousFee) {
		if (StringUtils.isBlank(suspiciousFee) || new BigDecimal(suspiciousFee).compareTo(BigDecimal.ZERO) == 0) {
			return BigDecimal.ZERO;
		}
		if (StringUtils.isBlank(hospitalTotal) || new BigDecimal(hospitalTotal).compareTo(BigDecimal.ZERO) == 0) {
			return BigDecimal.ZERO;
		}

		// 科室x的可疑金额占比=FWA审核出该科室住院的（一般可疑费用金额+严重可疑费用金额）/该科室住院费用*100%
		BigDecimal suspiFee = new BigDecimal(suspiciousFee);
		BigDecimal hospiFee = new BigDecimal(hospitalTotal);
		BigDecimal suspiciousPercent = suspiFee.divide(hospiFee, 3, BigDecimal.ROUND_HALF_UP);
		return suspiciousPercent;
	}

	/**
	 * 
	 * 拒付金额占比dxj
	 * @param hospitalTotal
	 * @return
	 */
	private BigDecimal getOutAmountPrecent(String hospitalTotal, String outOfLineAmount) {
		if (StringUtils.isBlank(outOfLineAmount) || new BigDecimal(outOfLineAmount).compareTo(BigDecimal.ZERO) == 0) {
			return BigDecimal.ZERO;
		}
		if (StringUtils.isBlank(hospitalTotal) || new BigDecimal(hospitalTotal).compareTo(BigDecimal.ZERO) == 0) {
			return BigDecimal.ZERO;
		}
		// 科室x的拒付金额占比=FWA审核出该科室住院的直接违规费用金额）/该科室住院费用*100%
		BigDecimal hospiFee = new BigDecimal(hospitalTotal);
		BigDecimal outAmountFee = new BigDecimal(outOfLineAmount);

		BigDecimal outAmountPrecent = outAmountFee.divide(hospiFee, 3, BigDecimal.ROUND_HALF_UP);
		return outAmountPrecent;
	}

	private Map<String, Object> getUniqueMedicalFeeResult(Map<String, List<BigDecimal>> listToResult,
			Map<String, String> kpiLimitParam) {
		Map<String, Object> resultMap = new HashMap<String, Object>();

		resultMap.put(
				"k2_1_1_1_health_flag_end",
				WordReportCalculateHelper.getInstance().getTotalFeeTendencyMessage(listToResult.get("monthChainList"),
						listToResult.get("monthPeriodList"), kpiLimitParam));
		resultMap.put("k2_1_1_1_yoy_flag_end",
				WordReportCalculateHelper.getInstance().getRatioCompareResult(listToResult.get("monthPeriodList")));
		resultMap.put("k2_1_1_1_mom_flag_end",
				WordReportCalculateHelper.getInstance().getRatioCompareResult(listToResult.get("monthChainList")));
		resultMap.put(
				"k2_1_1_1_yoy_result_end",
				WordReportCalculateHelper.getInstance().getRatioCompareScope(listToResult.get("monthPeriodList"),
						kpiLimitParam.get("periodUpper"), kpiLimitParam.get("periodDown")));
		resultMap.put(
				"k2_1_1_1_mom_result_end",
				WordReportCalculateHelper.getInstance().getRatioCompareScope(listToResult.get("monthChainList"),
						kpiLimitParam.get("chainUpper"), kpiLimitParam.get("chainDown")));
		resultMap.put(
				"k2_1_1_1_health_flag2_end",
				WordReportCalculateHelper.getInstance().getRiskMessage(
						listToResult.get("threeAvePredictPeriodRatioValList"),
						listToResult.get("threeAvePredictChainRatioValList"), kpiLimitParam));

		// resultMap.put("k2_allFeePredictValue_end", " ");
		// resultMap.put("k2_allPayedFeeValue_end", " ");
		// resultMap.put("k2_allPreAndPayedPercentageValue_end", " ");

		// 当月值
		resultMap.put(
				"k2_1_1_1_totalFee_end",
				GeneralMethods.getInstance().toFix2Digits(
						WordReportCalculateHelper.getInstance()
								.toFixedUniqueOrgList(listToResult.get("monthTotalPayList")).get(Constant.MONTH_ELEVEN)
								.doubleValue()));
		// 环比
		resultMap.put(
				"k2_1_1_1_mom_end",
				GeneralMethods.getInstance().toFix2Digits(
						WordReportCalculateHelper.getInstance().toFixedPercentList(listToResult.get("monthChainList"))
								.get(Constant.MONTH_ELEVEN).abs().doubleValue()));
		// 同比
		resultMap.put(
				"k2_1_1_1_yoy_end",
				GeneralMethods.getInstance().toFix2Digits(
						WordReportCalculateHelper.getInstance().toFixedPercentList(listToResult.get("monthPeriodList"))
								.get(Constant.MONTH_ELEVEN).abs().doubleValue()));
		resultMap
				.put("k2_1_1_1_totalFee_gqsnList_end",
						WordReportCalculateHelper.getInstance().toFixedUniqueOrgList(
								listToResult.get("monthAverageValueList")));
		resultMap.put("k2_1_1_1_totalFee_yc_yoyList_end",
				WordReportCalculateHelper.getInstance().toFixedPercentList(listToResult.get("monthPeriodList")));
		resultMap.put("k2_1_1_1_totalFee_yc_momList_end",
				WordReportCalculateHelper.getInstance().toFixedPercentList(listToResult.get("monthChainList")));
		resultMap.put("k2_1_1_1_totalFee_gqynList_end",
				WordReportCalculateHelper.getInstance().toFixedUniqueOrgList(listToResult.get("monthTotalPayList")));
		resultMap.put(
				"k2_1_1_1_totalFee_wlsyList_end",
				WordReportCalculateHelper.getInstance().toFixedUniqueOrgList(
						listToResult.get("threeAvePredictTotValList")));

		resultMap.put("k2_1_1_1_totalFee_yc_yoy_ycList_end", WordReportCalculateHelper.getInstance()
				.toFixedPercentList(listToResult.get("threeAvePredictPeriodRatioValList")));
		resultMap.put("k2_1_1_1_totalFee_yc_mom_ycList_end", WordReportCalculateHelper.getInstance()
				.toFixedPercentList(listToResult.get("threeAvePredictChainRatioValList")));
		checkTotalFeeLimitNull(kpiLimitParam, resultMap);
		return resultMap;
	}

	/**
	 * 
	 * 把对应的值封装成Map
	 * @param resultMap
	 * @param list
	 * @param visitType
	 */
	private void getAllDate(Map<String, Object> resultMap, List<FeeCheckDTO> list, String visitType) {
		BigDecimal outOfToallAmount = new BigDecimal(0);
		int outOfDeptNum = 0;
		BigDecimal outOfMax = new BigDecimal(0);
		String outOfDeptName = " ";

		for (FeeCheckDTO feeCheckDto : list) {
			BigDecimal outOfLineAmount = new BigDecimal(feeCheckDto.getOutOfLineAmount());
			// 共拒医疗费用
			outOfToallAmount = outOfToallAmount.add(outOfLineAmount);
			// 涉及科室
			if (!(outOfLineAmount.compareTo(BigDecimal.ZERO) == 0)) {
				outOfDeptNum++;
			}
			if (outOfLineAmount.compareTo(outOfMax) >= 0) {
				outOfMax = outOfLineAmount;
				outOfDeptName = feeCheckDto.getDeptName();
			}
		}
		if (outOfMax.compareTo(new BigDecimal(0)) == 0) {
			outOfDeptName = " ";
		}
		// 全院共拒付医疗费用_万元
		resultMap.put("k2_2_2_" + visitType + "_all_refuse_fee_end", WordReportCalculateHelper.getInstance()
				.yuanToTenThousands(outOfToallAmount).setScale(1, BigDecimal.ROUND_HALF_UP).toString());
		// 涉及_个科室
		resultMap.put("k2_2_2_" + visitType + "_all_dep_end", Integer.toString(outOfDeptNum));
		// 科室_为最高
		resultMap.put("k2_2_2_" + visitType + "_max_refuse_dep_end", outOfDeptName);
		// 拒付金额 _元
		resultMap.put("k2_2_2_" + visitType + "_max_refuse_fee_end", outOfMax.setScale(1, BigDecimal.ROUND_HALF_UP)
				.toString());

		getRefuseTop(resultMap, list, visitType);

	}

	private void getRefuseTop(Map<String, Object> resultMap, List<FeeCheckDTO> list, String visitType) {
		Collections.sort(list, new Comparator<FeeCheckDTO>() {
			public int compare(FeeCheckDTO arg0, FeeCheckDTO arg1) {
				return -(new BigDecimal(arg0.getOutAmountPercent()).compareTo(new BigDecimal(arg1.getOutAmountPercent())));
			}
		});

		if (list.size() > 10) {
			resultMap.put("k2_2_2_" + visitType + "_refuse_Fee_Cost_View_Line_List_end", new ArrayList<FeeCheckDTO>(
					list.subList(0, 10)));
		} else {
			resultMap.put("k2_2_2_" + visitType + "_refuse_Fee_Cost_View_Line_List_end", new ArrayList<FeeCheckDTO>(
					list));
		}
	}

	/**
	 * 
	 * 把对应的值封装成Map
	 * @param resultMap
	 * @param list
	 * @param visitType
	 */
	private void getSuspAllDate(Map<String, Object> resultMap, List<FeeCheckDTO> list, String visitType) {
		for (int i = 0; i < list.size(); i++) {
			if (new BigDecimal(list.get(i).getSuspiciousAmount()).compareTo(new BigDecimal(0)) <= 0) {
				list.remove(i);
			}
		}
		// 所有可疑金额
		BigDecimal suspiTotalAmout = new BigDecimal(0);
		// 涉及科室数量
		int suspiDeptNum = 0;
		// 最高可疑金额
		BigDecimal suspiMax = new BigDecimal(0);
		// 最高可疑金额科室
		String suspiDeptName = " ";

		for (FeeCheckDTO feeCheckDto : list) {
			BigDecimal suspiciousAmount = new BigDecimal(feeCheckDto.getSuspiciousAmount());
			suspiTotalAmout = suspiTotalAmout.add(suspiciousAmount);
			if (!(suspiTotalAmout.compareTo(BigDecimal.ZERO) == 0)) {
				suspiDeptNum++;
			}
			// 查询最高的
			if (suspiciousAmount.compareTo(suspiMax) >= 0) {
				suspiMax = suspiciousAmount;
				suspiDeptName = feeCheckDto.getDeptName();
			}
		}
		if (suspiMax.compareTo(new BigDecimal(0)) == 0) {
			suspiDeptName = " ";
		}
		// 可疑金额_万元
		resultMap.put("k2_2_2_" + visitType + "_all_suspicious_fee_end", WordReportCalculateHelper.getInstance()
				.yuanToTenThousands(suspiTotalAmout).setScale(1, BigDecimal.ROUND_HALF_UP).toString());
		// 涉及_个科室
		resultMap.put("k2_2_2_" + visitType + "_all_suspicious_dep_end", Integer.toString(suspiDeptNum));
		// 以科室_为最高
		resultMap.put("k2_2_2_" + visitType + "_max_suspicious_dep_end", suspiDeptName);
		// 涉及金额 _万元
		resultMap.put("k2_2_2_" + visitType + "_max_suspicious_fee_end", WordReportCalculateHelper.getInstance()
				.yuanToTenThousands(suspiMax).setScale(1, BigDecimal.ROUND_HALF_UP).toString());

		getSuspTop(resultMap, list, visitType);

	}

	private void getSuspTop(Map<String, Object> resultMap, List<FeeCheckDTO> list, String visitType) {
		Collections.sort(list, new Comparator<FeeCheckDTO>() {
			public int compare(FeeCheckDTO arg0, FeeCheckDTO arg1) {
				return -(new BigDecimal(arg0.getSuspAmountPercent()).compareTo(new BigDecimal(arg1
						.getSuspAmountPercent())));
			}
		});

		if (list.size() > 10) {
			resultMap.put("k2_2_2_" + visitType + "_susp_Fee_Cost_View_Line_List_end",
					new ArrayList<FeeCheckDTO>(list.subList(0, 10)));
		} else {
			resultMap
					.put("k2_2_2_" + visitType + "_susp_Fee_Cost_View_Line_List_end", new ArrayList<FeeCheckDTO>(list));
		}
	}

	private Map<String, Object> getPercentFee(Map<String, Object> param, Map<String, String> kpiLimitParam) {

		String kpiCode = KpiValueConst.KPI0002;
		String endDate = (String) param.get("currentDate");
		String startDate = WordReportCalculateHelper.getInstance().getStartDate(endDate, -Constant.MONTH_THIRTYFIVE);
		Map<String, Integer> orderMapthirtySix = WordReportCalculateHelper.getInstance().createOrderList(startDate,
				endDate);
		List<BigDecimal> periodList = WordReportCalculateHelper.getInstance().createSetListValue(
				orderMapthirtySix.size(), new BigDecimal(0));
		List<BigDecimal> chainList = WordReportCalculateHelper.getInstance().createSetListValue(
				orderMapthirtySix.size(), new BigDecimal(0));
		List<BigDecimal> totalPayList = WordReportCalculateHelper.getInstance().createSetListValue(
				orderMapthirtySix.size(), new BigDecimal(0));

		List<KpiSociationDTO> dataList = queryKpiSociationDTO(param, kpiCode);
		// 处理查询到对象的数值，将数据分装到相应的集合中
		getKpiSociationDTOKpiInfo(orderMapthirtySix, periodList, chainList, totalPayList, dataList);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		// 获取单一机构医保费用占比过去12个月同期平均值
		List<BigDecimal> monthAverageValueList = getMonthAverageValue(totalPayList);
		// 过去12个月的总值，环比值、同比值
		List<BigDecimal> monthTotalPayList = getMonthsList(totalPayList);
		List<BigDecimal> monthPeriodList = getMonthsList(periodList);
		List<BigDecimal> monthChainList = getMonthsList(chainList);
		// 获取过去12个月环比增长率总和平均值
		BigDecimal lastTwelveMonthAverageValue = getLastTwelveMonAve(monthChainList);
		// 未来三个月总费用占比预测
		List<BigDecimal> threeAvePredictTotValList = getThreeMonthpredictList(totalPayList, lastTwelveMonthAverageValue);

		// ----新计算方法---------------------开始------------------------
		// 同比预测
		List<BigDecimal> threeYearPeriodPredict = getPeriodRatioPredict(threeAvePredictTotValList, totalPayList,
				monthPeriodList);
		// 环比预测
		List<BigDecimal> threeYearChainPredict = getChainRatioPredict(threeAvePredictTotValList, monthChainList);

		// ----新计算方法---------------------结束------------------------------

		resultMap.put(
				"k0_1_1_2_Fee_Rate_end",
				GeneralMethods.getInstance().toFix2Digits(
						WordReportCalculateHelper.getInstance().toFixedPercentList(monthTotalPayList)
								.get(Constant.MONTH_ELEVEN).doubleValue()));// 当月值
		resultMap.put("k0_1_1_2_mom_end",
				GeneralMethods.getInstance()
						.toFix2Digits(monthChainList.get(Constant.MONTH_ELEVEN).abs().doubleValue()));// 环比

		resultMap.put(
				"k0_1_1_2_yoy_end",
				GeneralMethods.getInstance().toFix2Digits(
						monthPeriodList.get(Constant.MONTH_ELEVEN).abs().doubleValue()));// 同比

		resultMap.put("k0_1_1_2_Fee_Rate_gqsnList_end",
				WordReportCalculateHelper.getInstance().toFixedPercentList(monthAverageValueList));
		resultMap.put("k0_1_1_2_Fee_Rate_yoyList_end",
				WordReportCalculateHelper.getInstance().toFixedPercentList(monthPeriodList));

		resultMap.put("k0_1_1_2_Fee_Rate_momList_end",
				WordReportCalculateHelper.getInstance().toFixedPercentList(monthChainList));
		resultMap.put("k0_1_1_2_Fee_Rate_zjynList_end",
				WordReportCalculateHelper.getInstance().toFixedPercentList(monthTotalPayList));
		resultMap.put("k0_1_1_2_Fee_Rate_wlsyList_end",
				WordReportCalculateHelper.getInstance().toFixedPercentList(threeAvePredictTotValList));

		resultMap.put("k0_1_1_2_Fee_Rate_yoy_ycList_end",
				WordReportCalculateHelper.getInstance().toFixedPercentList(threeYearPeriodPredict));
		resultMap.put("k0_1_1_2_Fee_Rate_mom_ycList_end",
				WordReportCalculateHelper.getInstance().toFixedPercentList(threeYearChainPredict));
		// 如果取得阈值为空，直接将相应的信息置为空格，否则正常判断取得信息

		resultMap.put(
				"k0_1_1_2_health_flag_end",
				WordReportCalculateHelper.getInstance().getTotalFeeTendencyMessage(monthChainList, monthPeriodList,
						kpiLimitParam));

		resultMap.put("k0_1_1_2_yoy_flag_end",
				WordReportCalculateHelper.getInstance().getRatioCompareResult(monthPeriodList));
		resultMap.put("k0_1_1_2_mom_flag_end",
				WordReportCalculateHelper.getInstance().getRatioCompareResult(monthChainList));
		resultMap.put(
				"k0_1_1_2_yoy_result_end",
				WordReportCalculateHelper.getInstance().getRatioCompareScope(monthPeriodList,
						kpiLimitParam.get("periodUpper"), kpiLimitParam.get("periodDown")));
		resultMap.put(
				"k0_1_1_2_mom_result_end",
				WordReportCalculateHelper.getInstance().getRatioCompareScope(monthChainList,
						kpiLimitParam.get("chainUpper"), kpiLimitParam.get("chainDown")));
		resultMap.put(
				"k0_1_1_2_health_flag2_end",
				WordReportCalculateHelper.getInstance().getRiskMessage(threeYearPeriodPredict, threeYearChainPredict,
						kpiLimitParam));

		// 检查上下限的阈值是否出现空值，如果是空值将“ ” 返回对应的阈值
		checkTotalPercentNull(kpiLimitParam, resultMap);
		return resultMap;
	}

	private void checkTotalPercentNull(Map<String, String> kpiLimitParam, Map<String, Object> resultMap) {
		if (GeneralMethods.getInstance().isEmptyString(kpiLimitParam.get("periodUpper"))) {
			resultMap.put("KPI0002_yoy_upper_end", " ");
		} else {
			resultMap.put("KPI0002_yoy_upper_end", kpiLimitParam.get("periodUpper"));
		}
		if (GeneralMethods.getInstance().isEmptyString(kpiLimitParam.get("periodDown"))) {
			resultMap.put("KPI0002_yoy_lower_end", " ");
		} else {
			resultMap.put("KPI0002_yoy_lower_end", kpiLimitParam.get("periodDown"));
		}
		if (GeneralMethods.getInstance().isEmptyString(kpiLimitParam.get("chainUpper"))) {
			resultMap.put("KPI0002_mom_upper_end", " ");
		} else {
			resultMap.put("KPI0002_mom_upper_end", kpiLimitParam.get("chainUpper"));
		}
		if (GeneralMethods.getInstance().isEmptyString(kpiLimitParam.get("chainDown"))) {
			resultMap.put("KPI0002_mom_lower_end", " ");
		} else {
			resultMap.put("KPI0002_mom_lower_end", kpiLimitParam.get("chainDown"));
		}
	}

	/**
	 * Description:    单一机构总医保费用占比情况
	 * @param param   统筹区编码、指标时间
	 * @return   当期总医保费用占比值，过去12个月医保费用占比值、未来三个月的同比环比预测、过去12个月同期平均值等
	 * 
	 */
	private Map<String, Object> getPercentUniqueMedicalFee(Map<String, Object> param, Map<String, String> kpiLimitParam) {
		String regionCode = (String) param.get("regionCode");
		KpiConditionDTO conditionDTO = new KpiConditionDTO();
		List<String> kpiCodeList = new ArrayList<String>();
		kpiCodeList.add(KpiValueConst.KPI0002);
		conditionDTO.setOrgCode(param.get("medicalOrgCode").toString());
		conditionDTO.setKpiCodeList(kpiCodeList);
		conditionDTO.setSociationCode(regionCode);
		conditionDTO.setVisitType(Constant.VISIT_TYPE_ZERO);
		conditionDTO.setPeriod(Constant.TIME_TYPE_MONTH);
		String endDate = (String) param.get("currentDate");
		String startDate = WordReportCalculateHelper.getInstance().getStartDate(endDate, -Constant.MONTH_THIRTYFIVE);
		conditionDTO.setKpiTimeStart(startDate);
		conditionDTO.setKpiTimeEnd(endDate);

		Map<String, Integer> orderMapthirtySix = WordReportCalculateHelper.getInstance().createOrderList(startDate,
				endDate);
		// 同比
		List<BigDecimal> periodList = WordReportCalculateHelper.getInstance().createSetListValue(
				orderMapthirtySix.size(), new BigDecimal(0));
		// 环比
		List<BigDecimal> chainList = WordReportCalculateHelper.getInstance().createSetListValue(
				orderMapthirtySix.size(), new BigDecimal(0));
		// 总额
		List<BigDecimal> totalPayList = WordReportCalculateHelper.getInstance().createSetListValue(
				orderMapthirtySix.size(), new BigDecimal(0));
		List<KpiMedicalOrgDTO> kpiMedicalOrgList = kpiCoreDataService.queryKpiByOrg(conditionDTO);
		// 取出对象中的数据，处理相应数据
		getMedicalOrgDTOKpiInfo(orderMapthirtySix, periodList, chainList, totalPayList, kpiMedicalOrgList);
		// 获取过去12个总医保费用占比同期平均值
		List<BigDecimal> monthAverageValueList = getMonthAverageValue(totalPayList);
		// 获取过去12个月的医保费用占比值、同比值、环比值
		List<BigDecimal> monthTotalPayList = getMonthsList(totalPayList);
		List<BigDecimal> monthPeriodList = getMonthsList(periodList);
		List<BigDecimal> monthChainList = getMonthsList(chainList);
		// 获取过去12个月环比增长率总和平均值
		BigDecimal lastTwelveMonthAverageValue = getLastTwelveMonAve(monthChainList);
		// 获取未来三个月的医保费用占比预测值
		List<BigDecimal> threeAvePredictTotValList = getThreeMonthpredictList(totalPayList, lastTwelveMonthAverageValue);
		// ----新计算方法---------------------开始------------------------
		// 同比预测
		List<BigDecimal> threeYearPeriodPredict = getPeriodRatioPredict(threeAvePredictTotValList, totalPayList,
				monthPeriodList);
		// 环比预测
		List<BigDecimal> threeYearChainPredict = getChainRatioPredict(threeAvePredictTotValList, monthChainList);

		// ----新计算方法---------------------结束------------------------------

		Map<String, List<BigDecimal>> listToResult = new HashMap<String, List<BigDecimal>>();
		listToResult.put("monthTotalPayList",
				WordReportCalculateHelper.getInstance().toFixedPercentList(monthTotalPayList));
		listToResult
				.put("monthPeriodList", WordReportCalculateHelper.getInstance().toFixedPercentList(monthPeriodList));
		listToResult.put("monthChainList", WordReportCalculateHelper.getInstance().toFixedPercentList(monthChainList));
		listToResult.put("monthAverageValueList",
				WordReportCalculateHelper.getInstance().toFixedPercentList(monthAverageValueList));
		listToResult.put("threeAvePredictTotValList",
				WordReportCalculateHelper.getInstance().toFixedPercentList(threeAvePredictTotValList));
		listToResult.put("threeAvePredictChainRatioValList", WordReportCalculateHelper.getInstance()
				.toFixedPercentList(threeYearChainPredict));
		listToResult.put("threeAvePredictPeriodRatioValList", WordReportCalculateHelper.getInstance()
				.toFixedPercentList(threeYearPeriodPredict));
		// 将结果封装处理
		Map<String, Object> resultMap = getPercentUniqueMedicalFeeResult(listToResult, kpiLimitParam);

		return resultMap;
	}

	private void getMedicalOrgDTOKpiInfo(Map<String, Integer> orderMapthirtySix, List<BigDecimal> periodList,
			List<BigDecimal> chainList, List<BigDecimal> totalPayList, List<KpiMedicalOrgDTO> kpiMedicalOrgList) {
		String kpiTime;
		BigDecimal periodRatio;
		BigDecimal chainRatio;
		BigDecimal kpiValue;
		for (KpiMedicalOrgDTO kpiMedicalOrgDTO : kpiMedicalOrgList) {
			kpiValue = kpiMedicalOrgDTO.getKpiValue();
			periodRatio = kpiMedicalOrgDTO.getPeriodRatio();
			chainRatio = kpiMedicalOrgDTO.getChainRatio();
			kpiTime = GeneralMethods.getInstance().replacTimeFormate(kpiMedicalOrgDTO.getKpiTime());

			periodList.set(orderMapthirtySix.get(kpiTime),
					WordReportCalculateHelper.getInstance().filterNullValue(periodRatio));
			chainList.set(orderMapthirtySix.get(kpiTime),
					WordReportCalculateHelper.getInstance().filterNullValue(chainRatio));
			totalPayList.set(orderMapthirtySix.get(kpiTime),
					WordReportCalculateHelper.getInstance().filterNullValue(kpiValue));

		}
	}

	private Map<String, Object> getPercentUniqueMedicalFeeResult(Map<String, List<BigDecimal>> listToResult,
			Map<String, String> kpiLimitParam) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("k2_allFeePredictValue_end", " ");
		resultMap.put("k2_allPayedFeeValue_end", " ");
		resultMap.put("k2_allPreAndPayedPercentageValue_end", " ");
		// 住院
		resultMap.put("k2_hospRejectTotalFeeValue_end", " ");
		resultMap.put("k2_hospRejectRealteDepartmentAmount_end", " ");
		resultMap.put("k2_hospRejectHighestDepartment_end", " ");
		resultMap.put("k2_hospHighestDepartmentRejectValue_end", " ");
		resultMap.put("k2_hospTotalFeeValue_end", " ");
		resultMap.put("k2_hospRealteDepartmentAmount_end", " ");
		resultMap.put("k2_hospHighestDepartmentDoubleValue_end", " ");
		resultMap.put("k2_hospHighestDepartment_end", " ");
		// 门诊
		resultMap.put("k2_outRejectTotalFeeValue_end", " ");
		resultMap.put("k2_outRejectRealteDepartmentAmount_end", " ");
		resultMap.put("k2_outRejectHighestDepartment_end", " ");
		resultMap.put("k2_outHighestDepartmentRejectValue_end", " ");
		resultMap.put("k2_outTotalFeeValue_end", " ");
		resultMap.put("k2_outRealteDepartmentAmount_end", " ");
		resultMap.put("k2_outHighestDepartmentDoubleValue_end", " ");
		resultMap.put("k2_outHighestDepartment_end", " ");
		resultMap.put(
				"k2_1_1_2_fee_Rate_end",
				GeneralMethods.getInstance().toFix2Digits(
						listToResult.get("monthTotalPayList").get(Constant.MONTH_ELEVEN).doubleValue()));// 当月值
		resultMap.put(
				"k2_1_1_2_yoy_end",
				GeneralMethods.getInstance().toFix2Digits(
						listToResult.get("monthPeriodList").get(Constant.MONTH_ELEVEN).abs().doubleValue()));// 环比
		resultMap.put(
				"k2_1_1_2_mom_end",
				GeneralMethods.getInstance().toFix2Digits(
						listToResult.get("monthChainList").get(Constant.MONTH_ELEVEN).abs().doubleValue()));// 同比
		resultMap.put("k2_1_1_2_Fee_Rate_gqsnList_end", listToResult.get("monthAverageValueList"));
		resultMap.put("k2_1_1_2_Fee_Rate_yoyList_end", listToResult.get("monthPeriodList"));
		resultMap.put("k2_1_1_2_Fee_Rate_momList_end", listToResult.get("monthChainList"));
		resultMap.put("k2_1_1_2_Fee_Rate_zjynList_end", listToResult.get("monthTotalPayList"));
		resultMap.put("k2_1_1_2_Fee_Rate_wlsyList_end", listToResult.get("threeAvePredictTotValList"));
		resultMap.put("k2_1_1_2_Fee_Rate_yoy_ycList_end", listToResult.get("threeAvePredictPeriodRatioValList"));
		resultMap.put("k2_1_1_2_Fee_Rate_mom_ycList_end", listToResult.get("threeAvePredictChainRatioValList"));
		resultMap.put("k2_1_1_2_totalFee_yc_mom_ycList_end", listToResult.get("threeAvePredictChainRatioValList"));

		resultMap.put(
				"k2_1_1_2_health_flag_end",
				WordReportCalculateHelper.getInstance().getTotalFeeTendencyMessage(listToResult.get("monthChainList"),
						listToResult.get("monthPeriodList"), kpiLimitParam));
		resultMap.put("k2_1_1_2_yoy_flag_end",
				WordReportCalculateHelper.getInstance().getRatioCompareResult(listToResult.get("monthPeriodList")));
		resultMap.put("k2_1_1_2_mom_flag_end",
				WordReportCalculateHelper.getInstance().getRatioCompareResult(listToResult.get("monthChainList")));
		resultMap.put(
				"k2_1_1_2_yoy_result_end",
				WordReportCalculateHelper.getInstance().getRatioCompareScope(listToResult.get("monthPeriodList"),
						kpiLimitParam.get("periodUpper"), kpiLimitParam.get("periodDown")));
		resultMap.put(
				"k2_1_1_2_mom_result_end",
				WordReportCalculateHelper.getInstance().getRatioCompareScope(listToResult.get("monthChainList"),
						kpiLimitParam.get("chainUpper"), kpiLimitParam.get("chainDown")));
		resultMap.put(
				"k2_1_1_2_health_flag2_end",
				WordReportCalculateHelper.getInstance().getRiskMessage(
						listToResult.get("threeAvePredictPeriodRatioValList"),
						listToResult.get("threeAvePredictChainRatioValList"), kpiLimitParam));

		checkTotalPercentNull(kpiLimitParam, resultMap);
		return resultMap;
	}

	// -------------------------------nick--------------------------------
	@Override
	public Map<String, Object> getPercentPredict(Map<String, Object> param, Map<String, Object> kpiLimitParam) {

		String type = (String) param.get("type");
		Map<String, String> feePercentLimitlMap = new HashMap<String, String>();

		feePercentLimitlMap.put("periodUpper", (String) kpiLimitParam.get("KPI0002_yoy_upper_end"));
		feePercentLimitlMap.put("chainUpper", (String) kpiLimitParam.get("KPI0002_mom_upper_end"));
		feePercentLimitlMap.put("periodDown", (String) kpiLimitParam.get("KPI0002_yoy_lower_end"));
		feePercentLimitlMap.put("chainDown", (String) kpiLimitParam.get("KPI0002_mom_lower_end"));
		Map<String, Object> map = new HashMap<String, Object>();
		if ("0".equals(type)) {
			// 0：报告第一部分：月度总费用分析下医保费用占比
			map = getPercentFee(param, feePercentLimitlMap);
		} else if ("2".equals(type)) {
			// 2：报告第三部分：月度总费用和审查结果下医保费用占比
			map = getPercentUniqueMedicalFee(param, feePercentLimitlMap);
		}
		return map;
	}

	@Override
	public Map<String, Object> getTotalFeePredict(Map<String, Object> param, Map<String, Object> kpiLimitParam) {
		String type = (String) param.get("type");
		Map<String, Object> map = new HashMap<String, Object>();
		Map<String, String> totalFeeLimitlMap = new HashMap<String, String>();
		totalFeeLimitlMap.put("periodUpper", (String) kpiLimitParam.get("KPI0001_yoy_upper_end"));
		totalFeeLimitlMap.put("chainUpper", (String) kpiLimitParam.get("KPI0001_mom_upper_end"));
		totalFeeLimitlMap.put("periodDown", (String) kpiLimitParam.get("KPI0001_yoy_lower_end"));
		totalFeeLimitlMap.put("chainDown", (String) kpiLimitParam.get("KPI0001_mom_lower_end"));
		if ("0".equals(type)) {
			// 0：报告第一部分：总医疗费用
			map = getTotalFee(param, totalFeeLimitlMap);
		} else if ("1".equals(type)) {
			// 1：报告第二部分：月度费用对比分析
			map = getKipMapAll(param);
		} else if ("2".equals(type)) {
			// 2：报告第三部分：月度费用和审查结果
			map = getUniqueMedicalFee(param, totalFeeLimitlMap);
		}
		return map;
	}

	/**
	 * 
	 * 获得单一机构月度审查费用
	 * @param param
	 * @return
	 */
	@Override
	public Map<String, Object> getMonthCheckFee(Map<String, Object> param) {
		Map<String, Object> result = new HashMap<String, Object>();
		// 所有数据
		Map<String, List<FeeCheckDTO>> feeCheckReslt = new HashMap<String, List<FeeCheckDTO>>();
		// 查询单一机构的住院和门诊费用的科室的住院费用
		feeCheckReslt = this.queryAllHospitalFee(param, feeCheckReslt);

		List<FeeCheckDTO> hospitalRefuFeeList = feeCheckReslt.get("hospitalRefuFeeList");
		List<FeeCheckDTO> hospitalSuspFeeList = feeCheckReslt.get("hospitalSuspFeeList");
		List<FeeCheckDTO> outRefuFeeList = feeCheckReslt.get("outRefuFeeList");
		List<FeeCheckDTO> outSuspFeeList = feeCheckReslt.get("outSuspFeeList");

		// 把对应的值放入返回Map中
		getAllDate(result, hospitalRefuFeeList, "1");
		getSuspAllDate(result, hospitalSuspFeeList, "1");
		getAllDate(result, outRefuFeeList, "2");
		getSuspAllDate(result, outSuspFeeList, "2");
		return result;
	}

}
